﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Comod_Delivery : ATPages
{
    Function f = new Function();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            initgvData();
            lblPath.Text = f.getModuleidAdd(Request["moduid"]);
        }
    }
    protected void lnkbtnFlag_Click(object sender, EventArgs e)
    {
        string id = (sender as LinkButton).CommandArgument;
        ZSql zs = new ZSql();
        zs.Open("update CS_OutManage set isEnd=1 where OutBarCode='"+id+"'");
        zs.Close();
   
    }
    private void initgvData()
    {
        string sql = "select * from CS_OutManage where isEnd=0 order by OutShip desc";
        PageNavigator1.Total = 1;
        PageNavigator1.Query = sql;
    }

    protected void btnSelec_Click(object sender, EventArgs e)
    {
        string sql = "select * from CS_OutManage where 1=1";
        if (!string.IsNullOrEmpty(txtBarCode.Text))
        {
            sql += " and OutBarCode='" + txtBarCode.Text + "'";
        }
        if (!string.IsNullOrEmpty(txtselecName.Text))
        {
            sql += " and DeliveryMan='" + txtselecName.Text + "'";
        }
        sql += " and isEnd=" + ddlisOut.SelectedValue + " order by OutShip desc";
        PageNavigator1.Total = 1;
        PageNavigator1.Query = sql;
    }
    protected void GvDataBand_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string AuditState = DataBinder.Eval(e.Row.DataItem, "isEnd").ToString();

            if (AuditState == "1")
            {
                e.Row.Cells[6].Text = "已完成";
                e.Row.Cells[6].ForeColor = System.Drawing.Color.FromName("#ff0000");
            }
            if (AuditState == "0")
            {
                e.Row.Cells[6].Text = "送货中";
                e.Row.Cells[6].ForeColor = System.Drawing.Color.FromName("#ff0000");
            }

        }

    }
    protected void btndel_Click(object sender, EventArgs e)
    {
        ZSql del = new ZSql();
        int n = 0;
        if (this.GvDataBand.Rows.Count > 0)
        {
            for (int i = 0; i < GvDataBand.Rows.Count; i++)
            {
                CheckBox ck = GvDataBand.Rows[i].Cells[8].FindControl("chkDelete") as CheckBox;
                if (ck.Checked)
                {

                    del.Open("delete CS_OutManage  where OutShip=" + this.GvDataBand.Rows[i].Cells[0].Text);
                    ClientScript.RegisterStartupScript(typeof(Page), "aa", "alert('删除成功');", true);
                }
                else
                {
                    n++;
                }

                if (n == this.GvDataBand.Rows.Count)
                {

                    ClientScript.RegisterStartupScript(typeof(Page), "aa", "alert('至少应选择一项')", true);
                }

            }
        }
    }
}
